﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CVSToExcel
{
    public class FileItem : INotifyPropertyChanged
    {
       public FileItem() { }
       public FileItem(string fileName, string fullFileName)
       {
           this.FileNameOnly= fileName;
           this.FullFileName = fullFileName;
       }

       public string FileNameOnly { get; set; }

       public string FullFileName { get; set; }

       string _tabName;
       public string TabName
       {
           get
           {
               return ShortenName(30, _tabName);
           }
           set
           {
               _tabName = value;
               OnDisplayPropertyChanged();
           }
       }

       private string ShortenName(int maxLength, string tabName)
       {
           string fileName = string.IsNullOrEmpty(tabName) ? FileNameOnly : tabName;

           if (fileName.Length > maxLength)
               return fileName.Substring(0, maxLength);
           else
               return fileName;
       }

       public override string ToString()
       {
           return string.Format("{0}{1}", FileNameOnly, string.IsNullOrEmpty(TabName) ? "" : "(" + TabName + ")");
       }

       public string DisplayName
       {
           get
           {
               return string.Format("{0}{1}", FileNameOnly, string.IsNullOrEmpty(TabName) ? "" : "(" + TabName + ")");
           }
       }

       void OnDisplayPropertyChanged()
       {
           if (PropertyChanged != null)
               PropertyChanged(this, new PropertyChangedEventArgs("DisplayName"));
       }

       #region INotifyPropertyChanged Members

       public event PropertyChangedEventHandler PropertyChanged;

       #endregion
    }
}
